<template>
    <h2>显示列表</h2>
    卷标题：
    <input  type="text" v-model="name"/>
    适用门店:
    <input type="text" v-model="shopname"/>
    <input type="button" value="查询" @click="Show"/>
    <table border="1">
        <thead>
            <tr>
                <td>编号</td>
                <td>类型</td>
                <td>标题</td>
                <td>副标题</td>
                <td>图片</td>
                <td>剩余库存</td>
                <td>每人限领</td>
                <td>使用条件</td>
                <td>减免金额</td>
                <td>有效期</td>
                <td>适用业务</td>
                <td>须知</td>
                <td>适用门店</td>
                <td>服务电话</td>
                <td>操作</td>
            </tr>
        </thead>
        <tbody>
            <tr v-for="item in info">
                <td>{{item.dId}}</td>
                <td>{{item.type}}</td>
                <td>{{item.title}}</td>
                <td>{{item.fTitle}}</td>
                <td><img :src="item.imgUrl" style="width:70px;height:80px;"/></td>
                <td>{{item.kuCun}}</td>
                <td>{{item.num}}</td>
                <td>{{item.tiaoJian}}</td>
                <td>{{item.money}}</td>
                <td>{{item.statrTime}}-{{item.endTime}}</td>
                <td>{{item.yeWu}}</td>
                <td>{{item.xuZhi}}</td>
                 <td>{{item.shop}}</td>
                <td>{{item.phone}}</td>
                <td>
                    <input type="button" value="删除" @click="Shan(item.dId)"/>
                    <input type="button" value="修改" @click="Xiu(item.dId)"/>
                </td>
            </tr>
        </tbody>
    </table>
    总共有{{pageinfo.totalCount}}条数据
    总共有{{pageinfo.pageCount}}页
    当前第{{pageinfo.pageIndex}}/{{pageinfo.pageCount}}页

    <a href="#" @click="FanYe('F')">首页</a>
    <a href="#" @click="FanYe('L')">上一页</a>
    <a href="#" @click="FanYe('N')">下一页</a>
    <a href="#" @click="FanYe('N')">尾页</a>

    <select v-model="e" @change="Yema">
        <option :value="1">1条/页</option>
        <option :value="2">2条/页</option>
        <option :value="3">3条/页</option>
        <option :value="4">4条/页</option>
    </select>

    <input type="text" v-model="newye"/>
    <input type="button" value="跳转" @click="Tiao"/>

</template>
<script setup lang="ts">
   import {ref,onMounted} from 'vue';
    import axios from 'axios';
    import {useRoute,useRouter} from 'vue-router';

    const route=useRoute();
    const router=useRouter();

    const info=ref({
        dId:0,
        type: "",
        title: "",
        fTitle: "",
        imgUrl: "",
        kuCun: 0,
        num: 0,
        tiaoJian:"",
        money: 0,
        statrTime: "",
        endTime: "",
        yeWu: "",
        xuZhi: "",
        shop: "",
        phone: ""
    });

    onMounted(()=>{
        Show();
    })

    const pageinfo=ref({
        pageIndex:1,
        pageSize:2,
        totalCount:0,
        pageCount:0
    })

    const name=ref("");
    const shopname=ref("");

    const Show=()=>{
        axios.get("https://localhost:7034/api/Discount/GetDiscountByPage",{
            params:{
                PageIndex:pageinfo.value.pageIndex,
                PageSize:pageinfo.value.pageSize,
                name:name.value,
                shopname:shopname.value
            }
        })
        .then(res=>{
            console.log(res.data);
            info.value=res.data.discount_Info;
             pageinfo.value.pageCount=res.data.pageCount;
            pageinfo.value.totalCount=res.data.totalCount;
        })
        .catch(err=>{
            console.log(err);
        })
    }

    const FanYe=(choose:any)=>{
        switch(choose){
            case 'F':
                pageinfo.value.pageIndex=1;
            break;
            case 'L':
                pageinfo.value.pageIndex--;
            break;
            case 'N':
                pageinfo.value.pageIndex++;
            break;
            case 'E':
                pageinfo.value.pageIndex=pageinfo.value.pageCount;
            break;
        }
        Show();
    }

    const e=ref(0);
    const Yema=()=>{
        pageinfo.value.pageSize=e;
        Show();
    }

    const newye=ref(0);
    const Tiao=()=>{
        pageinfo.value.pageIndex=newye;
        Show();
    }

    const Shan=(dId:number)=>{
        if(confirm("确定要删除吗？")){
            axios.get("https://localhost:7034/api/Discount/DelDiscount",{
            params:{
                id:dId
            }
        })
        .then(res=>{
            if(res.data>0){
                alert('删除成功');
                Show();
            }
            else{
                alert('删除失败');
            }
        })
        }
    }

    const Xiu=(id:number)=>{
        router.push({
            name:"UpdateDiscount",
            params:{
                id:id
            }
        })
    }

</script>
